<template>
	<view class="sendInfosNoticeCom">
		<view class="topTitle">
			{{title}}
		</view>
		<view class="content">
			<view class="formBox">
				<u--form labelPosition="left" labelWidth='140' ref="uForm" :model="form" :rules="rules"
					:labelStyle="{fontWeight:700}">
					<u-form-item label="补全资料理由" labelWidth='200' prop="remindText" required>
						<view class="inputBox" id="searchSelectBox">
							<searchSelect :selectValue='form.remindText' currentCode='sendInfosNoticeCom'
								searchApi='sendInfosReason' :isDisabled='noticeType?true:false' :noticeType='noticeType'
								@refreshData="refreshSendInfosReason" placeholder='请选择补全资料类型'>
							</searchSelect>
						</view>
					</u-form-item>
					<view class="title">
						<view class="line"></view>
						需补寄如下资料:
					</view>
					<u-form-item label="蜡块" prop="waxBlock">
						<u--input v-model="form.waxBlock" placeholder="请输入蜡块几张"></u--input>
					</u-form-item>
					<u-form-item label="白片几张" prop="whitePiece">
						<u--input v-model="form.whitePiece" placeholder="请输入白片几张"></u--input>
					</u-form-item>
					<u-form-item label="HE切片几张" labelWidth='200rpx' prop="HE">
						<u--input v-model="form.HE" placeholder="请输入HE切片几张"></u--input>
					</u-form-item>
					<u-form-item label="免疫组化切片" labelWidth='200rpx' prop="immunohistochemical">
						<u--input v-model="form.immunohistochemical" placeholder="请输入免疫组化切片几张"></u--input>
					</u-form-item>
					<u-form-item label="放射胶片" prop="radiationFilm">
						<u--input v-model="form.radiationFilm" placeholder="请输入放射胶片几张"></u--input>
					</u-form-item>
					<u-form-item label="纸质文本" prop="paperText">
						<u--input v-model="form.paperText" placeholder="请输入纸质文本几张"></u--input>
					</u-form-item>
					<u-form-item label="备注" prop="remark">
						<u--input v-model="form.remark" placeholder="请输入备注"></u--input>
					</u-form-item>
					<view class="title">
						<view class="line"></view>
						已递交了如下资料:
					</view>
					<u-form-item label="蜡块" prop="waxBlock">
						<u--input disabled v-model="currentForm.waxBlock" placeholder="请输入蜡块几张"></u--input>
					</u-form-item>
					<u-form-item label="白片几张" prop="whitePiece">
						<u--input disabled v-model="currentForm.whitePiece" placeholder="请输入白片几张"></u--input>
					</u-form-item>
					<u-form-item label="HE切片几张" labelWidth='200rpx' prop="HE">
						<u--input disabled v-model="currentForm.HE" placeholder="请输入HE切片几张"></u--input>
					</u-form-item>
					<u-form-item label="免疫组化切片" labelWidth='200rpx' prop="immunohistochemical">
						<u--input disabled v-model="currentForm.immunohistochemical" placeholder="请输入免疫组化切片几张"></u--input>
					</u-form-item>
					<u-form-item label="放射胶片" prop="radiationFilm">
						<u--input disabled v-model="currentForm.radiationFilm" placeholder="请输入放射胶片几张"></u--input>
					</u-form-item>
					<u-form-item label="纸质文本" prop="paperText">
						<u--input disabled v-model="currentForm.paperText" placeholder="请输入纸质文本几张"></u--input>
					</u-form-item>
				</u--form>


			</view>

		</view>
		<view class="btnGroup">
			<u-button type="info" size="mini" text="关 闭" style="width:100rpx;margin:0rpx 24rpx;"
				@tap="cancelEvent"></u-button>
			<u-button type="primary" size="mini" text="确 定" style="width:100rpx;margin:0rpx 24rpx;"
				@tap="submitEvent"></u-button>
		</view>
	</view>
</template>

<script>
	import searchSelect from '@/components/searchSelect/searchSelect.vue'
	import {
		getDicts
	} from '@/api/platform/dicts.js'
	import {
		getExpressInfoningbo
	} from '@/api/platform/expressInfo.js'
	import {
		serviceReminderSave
	} from '@/api/platform/serviceReminder.js'
	export default {
		name: "sendInfosNoticeCom",
		props: ['orders', 'title', 'noticeType'],
		components: {
			searchSelect
		},
		data() {
			return {
				isReset: false,
				dictionaryMap: [ //PathologicalClass  病理分类
					{
						code: 'sendInfosReason',
						array: 'sendInfosReasonList'
					}
				],
				organsList: [],
				sendInfosReasonList: [],
				form: {
					orderId: this.orders.id,
					remindText: '',
					type: '', // 类型 1 系统自动 2 加做提醒 3 补充资料提醒 4 客服提醒 5 补寄
					status: 2, //0 无需处理 1 已处理 2 待处理	
				},
				currentForm: {

				},
				rules: {
					'remindText': [{
						type: 'string',
						required: true,
						message: '请选择补全资料理由',
						trigger: ['blur']
					}],
				},

			};
		},
		mounted() {
			// this.getSendInfosReasonList()
			this.getExpressInfoningbo()

		},
		methods: {
			refreshSendInfosReason(data) {
				if (data) {
					this.form.remindText = data.value
					this.getFormReasson(this.form.remindText)
				} else {
					this.form.remindText = ''
				}
			},
			getExpressInfoningbo() {
				getExpressInfoningbo(this.orders.id).then(res => {
					if (res.code === 200) {
						let data = res.data
						console.log(data)
						data.HE = data.he
						this.currentForm = data
					}
				})
			},
			getSendInfosReasonList() {
				let data = {
					page: 0,
					size: 99,
					code: "sendInfosReason"
				}
				getDicts(data).then(res => {
					if (res.code == 200) {
						let data = res.data
						this.list = []
						data.forEach(ele => {
							let obj = {
								text: ele.name,
								value: ele.name
							}
							this.list.push(obj)
						})
						if (this.noticeType) {
							let result = this.list.find(e => e.text.indexOf(this.noticeType) > -1)
							this.form.remindText = result.value
							this.getFormReasson(this.form.remindText)
							this.isReset = true
						} else {
							this.isReset = true
						}
					}
				})
			},
			//获取 资料补全通知
			getFormReasson(e) {
				if (e.indexOf('上传') > -1 || e.indexOf('补充') > -1) {
					this.form.type = '3'
				} else if (e.indexOf('补寄') > -1) {
					this.form.type = '5'
				}
				console.log(e)
			},
			cancelEvent() {
				this.$emit('close')
			},
			submitEvent() {
				this.$refs.uForm.validate().then(res => {
					this.saveServiceReminder()
				}).catch(errors => {})
			},
			// 新增  通知  serviceReminder/save
			saveServiceReminder() {
				if (this.form.type == '5') {
					if (!this.form.waxBlock && !this.form.whitePiece && !this.form.HE &&
						!this.form.immunohistochemical && !this.form.radiationFilm && !this.form.paperText) {
						this.$modal.showToast('需补寄资料不能为空~')
						return false
					}
				}
				let supplementaryContent = (this.form.waxBlock ? `蜡块${this.form.waxBlock}块、` : '') + (this.form
						.whitePiece ? `白片${this.form.whitePiece}块、` : '') +
					(this.form.HE ? `HE切片${this.form.HE}块、` : '') +
					(this.form.immunohistochemical ? `免疫组化切片${this.form.immunohistochemical}块、` : '') +
					(this.form.radiationFilm ? `放射胶片${this.form.radiationFilm}块、` : '') +
					(this.form.paperText ? `纸质文本${this.form.paperText}页` : '')
				let datacontentJson = {
					waxBlock: this.form.waxBlock,
					whitePiece: this.form.whitePiece,
					HE: this.form.HE,
					immunohistochemical: this.form.immunohistochemical,
					radiationFilm: this.form.radiationFilm,
					paperText: this.form.paperText
				}
				let data = {
					supplementaryContent: supplementaryContent,
					contentJson: JSON.stringify(datacontentJson),
					...this.form
				}
				serviceReminderSave(data).then(res => {
					if (res.code === 200) {
						// this.$modal.showToast('提交成功~')
						this.$emit("sendInfosEventSuccess")
					}
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	#searchSelectBox {
		/deep/ .uni-select__input-box {
			height: 28px;
		}

		/deep/ .uni-select {
			height: 28px;
			min-height: 28px;
			border: none;
			padding: 0px;
		}

		/deep/ .uni-icons {
			font-size: 20px !important;
		}

	}

	.sendInfosNoticeCom {
		width: 100%;
		height: 100%;

		.topTitle {
			text-align: center;
			font-size: 30rpx;
			font-weight: 700;
			line-height: 50rpx;
		}

		.content {
			height: calc(100% - 110rpx);
			padding: 0 24rpx;
			overflow-y: auto;

			.formBox {
				font-weight: normal;
				text-align: left;
				font-size: 30rpx;
				line-height: 40rpx;

				::v-deep .u-form-item__body {
					padding: 5rpx 0 !important;
				}

				.title {
					display: flex;
					align-items: center;
					color: #3898FF;
					margin: 18rpx 0;
					font-size: 28rpx;
					font-weight: bold;

					.line {
						width: 8rpx;
						height: 28rpx;
						background: #3898FF;
						border-radius: 8rpx;
						margin-right: 16rpx;
					}

					.tagBox {
						margin-left: 25rpx;
					}
				}

				.displaySpeen {
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.inputBox {
					width: 100%;
					height: 56rpx;
					padding: 9rpx 15rpx;
					border: 1px solid #E1E0E3;
					border-radius: 8rpx;
					display: flex;
					align-items: center;

				}
			}

		}

		.btnGroup {
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>